home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group93c.txt / 000047_icon-group-sender _Sun Sep 12 19:15:12 1993.msg < prev    next >
Internet Message Format  |  1994-02-02  |  2KB

  1. Received: from owl.CS.Arizona.EDU by cheltenham.cs.arizona.edu; Mon, 13 Sep 1993 07:33:29 MST
  2. Received: by owl.cs.arizona.edu; Mon, 13 Sep 1993 07:33:28 MST
  3. Date: 12 Sep 93 19:15:12 GMT
  4. From: ucivax!gateway@ucbvax.Berkeley.EDU  (Owen O'Malley)
  5. Subject: Re: Help on a simple problem.
  6. Message-Id: <3441.747861298@porte-de-st-ouen.ics.uci.edu>
  7. References: <26qre8INNq0g@dns1.NMSU.Edu>
  8. Sender: icon-group-request@cs.arizona.edu
  9. To: icon-group@cs.arizona.edu
  10. Status: R
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12.  
  13. >I have the following program that just computers a number to a certain
  14. >power....I also have it written to write the output to a file...my
  15. >problem is this...with very large numbers, i get a huge result
  16. >which ends up being written as 1 line.  Is there a way I could
  17. >split the output up so that it is written to numerous lines, 80 chars
  18. >per line. Ie: If you asked it to do 2 to the 5000th power you would
  19. >get a number that was 15-20 lines long...i need that to be printed
  20. >in a file as 15-20 seperate lines, not just one line.
  21.  
  22. The way that I would do it is:
  23.  
  24. # Note: I took the liberty of changing your algorithm so that it
  25. #       actually computes x^y
  26. # Line_Break take a character and prints it out, possibly with a line
  27. # break. I choose to make it handle a character, but you could easily
  28. # move the ! inside the procedure and pass in an entire string.
  29.  
  30. procedure Line_Break(ch)
  31.   static posn;
  32.   initial {posn:=1}
  33.   if posn > 72 then {
  34.     write();
  35.     posn := 1;
  36.   }
  37.   writes(ch);
  38.   posn +:= 1;
  39. end
  40.  
  41. procedure main()
  42.     write("Please enter a number. ")
  43.     n := read()
  44.     write("Please enter another number. ")
  45.     num:=read()
  46.     count:=1;
  47.     every 1 to num do {
  48.        count *:= n
  49.     }
  50.     write()
  51.     if num = 3 | num % 10 - 3 = 0 & num != 13 then
  52.         write(n, " to the ", num,"rd power is: ")
  53.     else if num = 2 | num % 10 - 2 = 0 & num != 12 then
  54.         write(n, " to the ", num,"nd power is: ")
  55.     else
  56.         write(n, " to the ", num, "th power is: ")
  57.         every Line_Break(!count);
  58.     write()
  59. end
  60.